<template>
	<view>
		<nav-bar title="我的团队" bgColor="#f5f5f5"></nav-bar>
        <!-- 公共组件-每个页面必须引入 -->
        <public-module></public-module>
		<!-- 菜单 -->
		<view class="menu_box">
			<view :class="{ active: menuType == 1 }" @click="onSelectMenuType(1)">一级（{{extendCount1}}）</view>
			<view :class="{ active: menuType == 2 }" v-if="distributionLevel >= 2" @click="onSelectMenuType(2)">二级（{{extendCount2}}）</view>
			<view :class="{ active: menuType == 3 }" v-if="distributionLevel >= 3" @click="onSelectMenuType(3)">三级（{{extendCount3}}）</view>
		</view>
		<view class="interval"></view>
        <mescroll-body ref="mescrollRef" height="-98" @init="mescrollInit" :down="downOption" @down="downCallback" @up="upCallback">
            <!-- 团队列表 -->
            <view class="team_lists_box">
                <view class="lists_box" v-for="(item,index) of extendLists" :key="index">
                    <view>
                        <view class="image_box"><image :src="item.userHeadImg" mode="aspectFill"></image></view>
                        <view class="info_box">
                            <view>
                                <text class="name">{{item.userNickName}}</text>
                                <text class="population">推广{{item.recommendNum}}人</text>
                            </view>
                            <view class="time">注册日期：{{item.createTime}}</view>
                        </view>
                    </view>
                </view>
            </view>
        </mescroll-body>
	</view>
</template>

<script>
import MescrollMixin from "@/components/common/mescroll-uni/mescroll-mixins.js";
    export default {
    	mixins: [MescrollMixin], // 使用mixin (在main.js注册全局组件)
	data() {
		return {
			menuType: 1,
			downOption: {
				auto: false //是否在初始化后,自动执行downCallback; 默认true
			},
			extendLists:[],
			extendCount1:0,
			extendCount2:0,
			extendCount3:0,
			distributionLevel:0
		};
	},
	//第一次加载
	onLoad(e) {
		if(this.$base.module.distributionLevel){
			this.distributionLevel = this.$base.module.distributionLevel;
		}
		if(e.numOne){
			this.extendCount1 = e.numOne;
		}
		if(e.numThree){
			this.extendCount3 = e.numThree;
		}
		if(e.numTwo){
			this.extendCount2 = e.numTwo;
		}
		this.loadData(1,1);
		this.loadData(1,2);
	},
	//页面显示
	onShow() {},
	//方法
	methods: {
		// 菜单筛选
		onSelectMenuType(menuType) {
			this.menuType = menuType;
			this.mescroll.triggerDownScroll();
		},
        /*下拉刷新的回调 */
        downCallback() {
        	//联网加载数据
        	this.loadData(1, this.menuType);
        },
        /*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
        upCallback(page) {
        	//联网加载数据
        	this.loadData(page.num, this.menuType);
        },
        loadData(pageNo, level) {
            let httpData = {
                pageNo: pageNo,
                pageSize: 15,
                level : level
            };
            this.$http
            	.post('api/mime/spread/v1/list', httpData,{
            		load:false
            	}).then(res => {
            		uni.stopPullDownRefresh();
                    if(this.menuType == level ){
                        //方法一(推荐): 后台接口有返回列表的总页数 totalPage
                        this.mescroll.endByPage(res.data.length, res.pages); //必传参数(当前页的数据个数, 总页数)
                    	if (pageNo == 1) {
                    		this.extendLists = res.data;
                    	} else {
                    		this.extendLists = this.extendLists.concat(res.data);
                    	}
                    }
                    this["extendCount"+level] = res.count;
            	}).catch(() => {
            		//联网失败, 结束加载
            		this.mescroll.endErr();
            	});
        },
	},
	//页面隐藏
	onHide() {},
	//页面卸载
	onUnload() {},
	//用户点击分享
	onShareAppMessage(e) {
		return this.wxShare();
	}
};
</script>
<style lang="scss" scoped>
@import '@/style/mixin.scss';
.interval {
	height: 100rpx;
}
.menu_box {
	height: 88rpx;
	background-color: #ffffff;
	padding: 31rpx 48rpx 10rpx;
	border-bottom: 1rpx solid #e5e5e5;
	display: flex;
	justify-content: space-between;
	align-items: center;
	position: fixed;
	left: 0;
	width: 100%;
	z-index: 2;
	> view {
		flex: 1;
		display: flex;
		align-items: center;
		justify-content: center;
		flex-direction: column;
		font-size: 28rpx;
		color: #333333;
		&::after {
			content: '';
			width: 40rpx;
			height: 6rpx;
			margin-top: 24rpx;
		}
		&.active {
			@include  theme('font');
			&::after {
				content: '';
				width: 40rpx;
				height: 6rpx;
				@include  theme('bg');
				border-radius: 3rpx;
				margin-top: 24rpx;
			}
		}
	}
}
.team_lists_box {
	.lists_box {
		margin-bottom: 20rpx;
		background-color: #ffffff;
		> view {
			&:nth-of-type(1) {
				padding: 20rpx 30rpx;
				border-bottom: 1rpx solid #e5e5e5;
				display: flex;
				justify-content: flex-start;
				align-items: center;
				.image_box {
					image {
						width: 100rpx;
						height: 100rpx;
					}
				}
				.info_box {
					margin-left: 30rpx;
					height: 100rpx;
					display: flex;
					justify-content: space-around;
					flex-direction: column;
					width: 100%;
					> view {
						&:nth-of-type(1) {
							display: flex;
							justify-content: space-between;
							align-items: baseline;
							.name {
								font-size: 28rpx;
								color: #333333;
							}
							.population {
								font-size: 24rpx;
								color: #999999;
							}
						}
						&.time {
							font-size: 24rpx;
							color: #999999;
						}
					}
				}
			}
		}
	}
}
</style>
